package com.zy.基础.伴生对象

class Student(var name: String, var age: Int) {

  def print(): Unit = {
    println("name=" + name + ",age=" + age + ",say=" + Student.say)
  }
}

/**
 * 伴生对象，一定与对应的class同名，且在同一个文件中
 * object下所有的属性都会默认加上类似java的<static>标签，所以可以使用<类名.属性名>直接调用
 */
object Student {
  val say: String = "Hello Scala"

  def main(args: Array[String]): Unit = {
    val student1 = new Student("张三", 12)
    val student2 = new Student("李四", 15)

    student1.print()
    student2.print()
  }
}
